package com.admin.education.models;


import com.admin.education.models.Enum.QuestionType;
import com.admin.education.repositories.Identifiable;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.List;

@Entity
@Table(name = "questions")
@EntityListeners(AuditingEntityListener.class)
@Data
public class Questions implements Serializable ,Identifiable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;
    @Column(name="examination_questions")
    @NotBlank
    @Length(max=1024)
    private String examinationQuestions;
    @Column(name = "question_type")
    @NotNull
    private QuestionType questionType;

    @OneToMany(cascade = CascadeType.ALL,fetch = FetchType.LAZY,mappedBy = "questions")
    @JSONField(serialize=false)
    private List<Answers> answeres;
    @OneToOne(fetch = FetchType.LAZY)
    @NotNull
    @JSONField(serialize=false)
    private Subjects subjects;
    @Column(name="mark")
    @NotNull
    @DecimalMin(value = "0")
    private BigDecimal mark;

}
